﻿using System;
using System.Drawing;
using System.Windows.Forms;
using BasecampRestAPI;
using BasecampUI;

namespace MoveToDoList
{
	public partial class MainForm : Form, IMainForm
	{
		private readonly MainFormMediator _mediator;
		private readonly ProjectToDoListsAdapter _sourceProject;
		private readonly ProjectToDoListsAdapter _targetProject;
		private readonly CredentialsMainFormMediator _credentialsMediator;

		public MainForm()
		{
			InitializeComponent();
			deleteButton.ImageList.TransparentColor = Color.Magenta;
			_mediator = MainFormMediator.GetInstance(this);
			_credentialsMediator = CredentialsMainFormMediator.GetInstance(this);
			_sourceProject = ProjectToDoListsAdapter.GetInstance(sourceProjectComboBox, sourceToDoListsListBox);
			_targetProject = ProjectToDoListsAdapter.GetInstance(targetProjectComboBox, targetToDoListsListBox);
		}

		private void MainForm_Load(object sender, EventArgs e)
		{
			_mediator.Load();
		}

		#region Implementation of IMainForm

		public IProjectToDoLists SourceProject
		{
			get { return _sourceProject; }
		}
		public IProjectToDoLists TargetProject
		{
			get { return _targetProject; }
		}

		public ICredentialsForm CredentialsForm
		{
			get { return new CredentialsForm(); }
		}

		public IBaseCamp GetBaseCamp(IRestWebService service)
		{
			return BaseCamp.GetInstance(service);
		}

		public bool GetBaseCampFromCredentials(out IBaseCamp camp)
		{
			return _credentialsMediator.GetBaseCampFromCredentials(out camp);
		}

		#endregion

		private void sourceProjectComboBox_SelectionChangeCommitted(object sender, EventArgs e)
		{
			_mediator.SourceProjectSelectedIndexChanged();
		}

		private void targetProjectComboBox_SelectionChangeCommitted(object sender, EventArgs e)
		{
			_mediator.TargetProjectSelectedIndexChanged();
		}

		private void moveButton_Click(object sender, EventArgs e)
		{
			_mediator.MoveButtonClick();
		}

		private void deleteButton_Click(object sender, EventArgs e)
		{
			_mediator.DeleteButtonClick();
		}
	}
}
